﻿@{
    Layout = null;
    var plugName = @brand.admin.cyt369.com.Areas.BrandAdmin.Models.PlugName.Name;
    var tableName = PageViewModel.PageTableID(this, plugName);
    var tableToolBar = PageViewModel.PageTableToolbar(this, plugName);
    var tableToolBarSearch = PageViewModel.PageTableToolbarSearch(this);
    var tableToolBarReset = PageViewModel.PageTableToolbarReset(this);

    var viewFunName = PageViewModel.PageFunctionName(this, "view_brand", plugName);
    var viewDlgName = PageViewModel.PageEditDialog(this, "view", plugName);

    var auditLogFunName = PageViewModel.PageFunctionName(this, "view_audit_log", plugName);
    var auditLogDlgName = PageViewModel.PageEditDialog(this, "audit_log_dlg", plugName);

    var imgFmtFun = PageViewModel.PageFunctionName(this, "img_fmt", plugName);
    var amountFmtFun = PageViewModel.PageFunctionName(this, "amount_fmt", plugName);
    var brandFmtFun = PageViewModel.PageFunctionName(this, "brand_fmt", plugName);
    var auditLogFmtFun = PageViewModel.PageFunctionName(this, "audit_log_fmt", plugName);
    var cityTypeFmtFun = PageViewModel.PageFunctionName(this, "cityType_fmt", plugName);
    var categoryIDFmtFun = PageViewModel.PageFunctionName(this, "CategoryID_fmt", plugName);
}
<style>
    .brandImage {
        width: 130px;
        height: 80px
    }
</style>

<div style="height:100%">
    <script type="text/javascript">
        function @(viewFunName)(id) {
            var dlg = $dlg('@viewDlgName');
            dlg.dialog({
                title: '内容预览', width: 1000, height: 600,
                closed: false, cache: false, modal: true, maximizable: true, resizable: true, maximized: true,
                href: '~/@plugName/Brand/_ViewBrandDlg/' + id + '?dlg=@viewDlgName',
                onResize: function () {
                    $(this).dialog('center');
                }
            });
        }

        function @(auditLogFunName)(id) {
            var dlg = $dlg('@auditLogDlgName');
            dlg.dialog({
                title: '审核记录', width: 1000, height: 600,
                closed: false, cache: false, modal: true, maximizable: true, resizable: true, maximized: false,
                href: '~/@plugName/Brand/_AuditLogDlg/' + id + '?dlg=@auditLogDlgName',
                onResize: function () {
                    $(this).dialog('center');
                }
            });
        }
    </script>

    <script type="text/javascript">
        function @tableToolBarSearch{
            $('#@tableName').datagrid('load', {
                Title: $("#@tableToolBar").find("#_Title").textbox("getValue"),
            });
        }

        function @tableToolBarReset{
            $("#@tableToolBar").find("#_Title").textbox("setValue", "");
        @(tableToolBarSearch)();
                                }
    </script>

    <script type="text/javascript">
        function @(imgFmtFun)(v, r, i){
            let result = ""
            let brandImags = GetObject(r.Id, '~/@plugName/Brand/GetBrandImagesByBrandID/');
            if (brandImags == null || brandImags.length == 0) {
                result = `<img src="images/index/bug_320x320.jpg"  alt="${r.Name}" class="brandImage"></img>`;
            } else {
                let imgPath = "@Admin.CYT369.Com.Utility.SystemSettingService.Instance.BrandBucket.HttpURL" + "/" + brandImags[0].ImagePath
                result = `<img src="${imgPath}" class="brandImage"></img>`;
            }
            return result;
        }

        function @(amountFmtFun)(v, r, i){
            if (r.Amount == 1) { return "5万以下"; }
            else if (r.Amount == 2) { return "5~10万"; }
            else if (r.Amount == 3) { return "10~20万"; }
            else if (r.Amount == 4) { return "20~50万"; }
            else if (r.Amount == 5) { return "50~100万"; }
            else if (r.Amount == 6) { return "100以上"; }
            else { return ""; }
        }

        function @(brandFmtFun)(v, r, i) {
            return "<a href='javascript:@viewFunName (" + r.Id + ")'>" + v + "</a>";
        }

        function @(auditLogFmtFun)(v, r, i) {
            return "<a href='javascript:@auditLogFunName (" + r.Id + ")'>审核记录</a>";
        }

        function @(categoryIDFmtFun)(v, r, i) {
            var v = GetObject(v, '~/@plugName/Category/GetCategoryByID');
            if (v != null) { return v.CategoryName; }
        }

        function @(cityTypeFmtFun)(v, r, i) {
            var v = GetObject(v, '~/@plugName/City/GetCityByID');
            if (v != null) { return v.CityName; }
        }

    </script>

    <table id="@tableName" class="easyui-datagrid" style="width:100%;" rownumbers="true" fit="true"
           pagination="true" pageSize="@SystemSettingService.Instance.PageSize" pageList="@SystemSettingService.Instance.PageList"
           data-options="striped:true,border:false,singleSelect:true,url:'~/@plugName/Brand/GetDeleteBrands',method:'get',toolbar:'#@tableToolBar'">
        <thead>
            <tr>
                <th data-options="field:'_audit',align:'center',formatter:@auditLogFmtFun" width="80">审核记录</th>
                <th data-options="field:'_img',formatter:@imgFmtFun" width="150">品牌图片</th>
                <th data-options="field:'Name',formatter:@brandFmtFun" width="200">品牌名称</th>
                <th data-options="field:'Amount',align:'center',formatter:@amountFmtFun" width="80">投资金额</th>
                <th data-options="field:'CategoryID',align:'center',formatter:@categoryIDFmtFun" width="80">品牌类型</th>
                <th data-options="field:'FranchiseRegionID',align:'center',formatter:@cityTypeFmtFun" width="80">加盟地区</th>
                <th data-options="field:'StoreCount',align:'center'" width="80">门店数量</th>
                <th data-options="field:'InquiryCount',align:'center'" width="80">咨询人数</th>
                <th data-options="field:'MainProduct',align:'center'" width="200">主营产品</th>
                <th data-options="field:'TargetAudience',align:'center'" width="200">适合人群</th>
                <th data-options="field:'DevelopmentModel',align:'center'" width="200">发展模式</th>
                <th data-options="field:'FranchiseWebsite',align:'center'" width="200">招商网址</th>
                <th data-options="field:'CreatorFullName'" width="100">创建者</th>
                <th data-options="field:'CreateDate',align:'center',formatter:$.DateTimeFmt" width="150">创建时间</th>
                <th data-options="field:'EditorName'" width="100">编辑</th>
                <th data-options="field:'EditorFullName'" width="100">编辑姓名</th>
                <th data-options="field:'EditDate',align:'center',formatter:$.DateTimeFmt" width="150">修改时间</th>
            </tr>
        </thead>
    </table>
    <div id="@tableToolBar" class="table-toolbar">
        <ul class="query-body">
            <li>
                <span>标题：</span>
                <input id="_Title" class="easyui-textbox" />
            </li>
            <li>
                <a href="javascript:@tableToolBarSearch" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a>
                <a href="javascript:@tableToolBarReset" class="easyui-linkbutton" data-options="iconCls:'icon-reload'">重置</a>
            </li>
        </ul>
    </div>
</div>
